package com.fanhang.samples.mongodb.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import com.fanhang.samples.mongodb.dao.UserDao;
import com.fanhang.samples.mongodb.po.User;
import com.fanhang.samples.mongodb.repository.UserRepository;

@Repository
public class UserDaoImpl implements UserDao {
	
	@Autowired
	private MongoTemplate mongoTemplate;
	@Autowired
	private UserRepository userRepository;
	
	@Override
	public void save(User user) {
		userRepository.save(user);
	}

	@Override
	public User get(User user) {
		return mongoTemplate.findOne(new Query(Criteria.where("name")), User.class);
	}

	@Override
	public List<User> getList(User user) {
		return mongoTemplate.find(new Query(Criteria.where("name")), User.class);
	}

}
